<?php
/*
 * 车型库扩展字段管理文件
 * @package    auto
 * @author     Mark
 * @copyright  Copyright (c) 2013 ixdcw team
 * @version    $Id: 7e2cfb43884898eedfee5b7c6bbf01b31d0e71c4 $
 */
defined('IN_IXDCW') or exit('Access Denied');
$tb = isset($tb) ? trim($tb) : '';
$tb or msg();
$len = strlen($db->getPre());
if(substr($tb, 0, $len) == $db->getPre()) $tb = substr($tb, $len);
$do = new AutoFieldModule();
$do->setTb($tb);
$menus = array (
    array('添加字段', '?moduleid='.$moduleid.'&file='.$file.'&tb='.$tb.'&action=add'),
    array('字段列表', '?moduleid='.$moduleid.'&file='.$file.'&tb='.$tb),
);
$this_forward = '?moduleid='.$moduleid.'&file='.$file.'&tb='.$tb;
switch($action) {
	case 'add':
		if($submit) {
			if($do->pass($post)) {
				$do->add($post);
				dmsg('添加成功', $this_forward);
			} else {
				msg($do->getErrmsg());
			}
		} else {
			include tpl('fields_add', $module);
		}
	break;
	case 'edit':
		$itemid or msg();
		$do->setItemid($itemid);
		if($submit) {
			if($do->pass($post)) {
				$do->edit($post);
				dmsg('修改成功', $this_forward);
			} else {
				msg($do->getErrmsg());
			}
		} else {
			extract($do->getOne());
			include tpl('fields_edit', $module);
		}
	break;
	case 'delete':
		$itemid or msg();
		$do->delete($itemid);
		dmsg('删除成功', $this_forward);
	break;
	case 'order':
		$do->order($listorder);
		dmsg('更新成功', $this_forward);
	break;
	default:
		$lists = $do->getList("tb='$tb'");
		PCache::sysAutoFields($tb);
		include tpl('fields', $module);
	break;
}